;-----------------------------------------------------------------;
;  Copyright (C) 2011, Ryabov Alex. All rights reserved.          ;
;  Distributed under terms of the GNU General Public License.     ;
;  See file COPYING for details.                                  ;
;-----------------------------------------------------------------;
;  Omaha32                                                        ;
;  /sys32/spinlocks.inc                                           ;
;-----------------------------------------------------------------;


struc sys_mutexes {
  .paging  dd  0
  .tasks   dd  0
  .dlls    dd  0
}

sys_mutexes sys_mutexes

; ebx = mutex
; test and set mutex
wait_mutex:
  push ebx eax
.do_wait:
  bts dword [ebx],0
  jnc .locked
  ;call change_task
  jmp .do_wait
.locked:
  pop eax ebx
  ret

; ebx = mutex
; release mutex
free_mutex:
  dec dword [ebx]
  ret